

package top.continew.admin.question.user.service.questionset.enums;

import lombok.Getter;
import top.continew.admin.question.user.service.questionset.entity.AbstractQuestionSet;
import top.continew.admin.question.user.service.questionset.entity.KnowledgePointQuestionSet;
import top.continew.admin.question.user.service.questionset.entity.WrongQuestionSet;
import top.continew.admin.question.user.service.questionset.entity.SpecialPracticeQuestionSet;

import java.util.Map;
import java.util.function.Function;

public enum QuestionSetTypeEnum {
    //    LY_TRUE_QUESTION(1, "历年真题"),
    //    SIMULATION_EXERCISE(2, "模拟练习"),
    KNOWLEDGE_POINT_EXERCISE(3, "知识点练习", (knowledgePointId) -> new KnowledgePointQuestionSet(Long.parseLong(String
        .valueOf(knowledgePointId)))),
    //    HOMEWORK(4, "作业"),
    WRONG_QUESTION(5, "错题", (userId -> new WrongQuestionSet(Long.parseLong(String.valueOf(userId))))),
    SPECIAL_PRACTICE(6, "专项练习", (map -> {
        Map<String, Long> mapS = (Map<String, Long>)map;
        return new SpecialPracticeQuestionSet(mapS.get("userId"), mapS.get("knowledgeId"));
    }));

    //    COLLECTION(6, "收藏"),
    //    NOTE(7, "小记");
    @Getter
    private final Integer code;
    @Getter
    private final String name;
    @Getter
    private final Function<Object, AbstractQuestionSet> function;

    QuestionSetTypeEnum(Integer code, String name, Function<Object, AbstractQuestionSet> function) {
        this.code = code;
        this.name = name;
        this.function = function;
    }

    //根据code获取枚举
    public static QuestionSetTypeEnum getEnumByCode(Integer code) {
        for (QuestionSetTypeEnum value : QuestionSetTypeEnum.values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }
}
